package com.rainng.coursesystem.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.rainng.coursesystem.base.api.dto.PagingReqDTO;
import com.rainng.coursesystem.controller.BaseController;
import com.rainng.coursesystem.model.entity.CodeWhiteEntity;
import com.rainng.coursesystem.model.shitong.*;
import com.rainng.coursesystem.model.taskplan.PlanStateUpdateVo;
import com.rainng.coursesystem.model.taskplan.PlanUpdateVo;
import com.rainng.coursesystem.model.taskplan.PlanVo;
import com.rainng.coursesystem.model.taskplan.DeliveryVo;
import com.rainng.coursesystem.model.taskplan.ReturnVo;
import com.rainng.coursesystem.model.entity.TrialProjectNumEntity;
import com.rainng.coursesystem.model.vo.response.ResultVO;
import com.rainng.coursesystem.model.entity.TireInfoEntity;
import com.rainng.coursesystem.model.entity.TakePhotoItemsEntity;
import com.rainng.coursesystem.model.entity.TrialProjectsEntity;
import com.rainng.coursesystem.module.task.dto.request.TaskCarDTO;
import com.rainng.coursesystem.module.task.dto.response.TaskCarResDTO;
import com.rainng.coursesystem.service.CheckFileService;
import com.rainng.coursesystem.service.PlanService;
import com.rainng.coursesystem.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.rainng.coursesystem.model.constant.GeneralReportProjectMap.*;


@Api(tags = "试验计划")
@RequestMapping("/v2/task/plan")
@RestController
public class PlanController extends BaseController {

    @Resource
    private PlanService service;



    @PostMapping("/page/count")
    @ApiOperation(value = "返回分页查询数量")
    public ResultVO listCount(@RequestBody PlanVo cvo) {
        return service.countPlan(cvo);
    }

    @PostMapping("/page")
    @ApiOperation(value = "分页查询")
    public ResultVO listPage(@RequestBody PlanVo cvo) {
        List<Object> lists = service.selectPlan(cvo);
        return super.result(lists);
    }

    @PostMapping("/save")
    @ApiOperation(value = "新增计划")
    public ResultVO savePlan(@RequestBody PlanVo vo) {
        return service.saveTaskPlan(vo);
    }

    @PostMapping("/update")
    @ApiOperation(value = "更新计划")
    public ResultVO getDetail(@RequestBody PlanUpdateVo vo) {
        return service.updatePlan(vo);
    }

    @PostMapping("/update/state")
    @ApiOperation(value = "更新计划计划状态")
    public ResultVO getDetailState(@RequestBody PlanStateUpdateVo vo) {
        return service.updatePlanState(vo);
    }


    @GetMapping("/detail/{id}")
    @ApiOperation(value = "根据id获取计划详情")
    public ResultVO detailPlan(@PathVariable String id) {
        return service.getPlanDetailById(id);

    }

    @GetMapping("/delete/{id}")
    @ApiOperation(value = "根据id删除数据")
    public ResultVO deletePlan(@PathVariable String id) {
        return service.deletePlanById(id);

    }



    @GetMapping("/info/{id}")
    @ApiOperation(value = "根据任务编号获取任务信息")
    public ResultVO getTaskDetail(@PathVariable String id) {
        return service.getTaskInfoByTaskCode(id);

    }
    @PostMapping("/getTrialProject")
    @ApiOperation(value = "获取需要实测的项目")
    public ResultVO getTrialProject(@PathVariable TrialProjectNumEntity req) {
        TrialProjectNumEntity res =  service.getTrialProject(req.getApplyNum());
        return super.result(res);
    }

    @GetMapping("/getTireList/{vin}")
    @ApiOperation(value = "获取轮胎信息")
    public ResultVO<TaskCarResDTO>getTireList(@PathVariable String vin) {
        List<TireInfoEntity> res = service.getTireList(vin);
        return super.result(res);
    }
    @PostMapping("/getPhotoItems")
    @ApiOperation(value = "拍照条目查询")
    public ResultVO getPhotoItems(@RequestBody PagingReqDTO<TakePhotoItemsEntity> reqDTO) {
        IPage<TakePhotoItemsEntity> res = service.getPhotoItems(reqDTO);
        List<TakePhotoItemsEntity> list = res.getRecords();
        Integer n = 1;
        for(TakePhotoItemsEntity t :list){
            // t.setOrder(n.toString());
            n ++;
        }
        return super.result(res);
    }
    @PostMapping("/saveTakePhotosItems")
    @ApiOperation(value = "拍照条目保存")
    public ResultVO saveTakePhotosItems(@RequestBody TakePhotoItemsEntity reqDto) {
        return service.saveTakePhotosItems(reqDto);
    }
    @PostMapping("/deleteTakePhotosItems")
    @ApiOperation(value = "拍照条目删除")
    public ResultVO deleteTakePhotosItems(@RequestBody TakePhotoItemsEntity reqDto) {
        return service.deleteTakePhotosItems(reqDto);
    }
    @PostMapping("/updateTakePhotosItems")
    @ApiOperation(value = "白拍照条目更新")
    public ResultVO updateTakePhotosItems(@RequestBody TakePhotoItemsEntity reqDto) {
        return service.updateTakePhotosItems(reqDto);
    }
    @PostMapping("/getTrialProjectsByUserId")
    @ApiOperation(value = "小程序根据用户id获取拍照条目")
    public ResultVO getTrialProjectsByUserId(@RequestBody Map<String, String> requestBody) {
        List<TrialProjectsEntity> res = service.getTrialProjectsByUserId(requestBody.get("userId"), requestBody.get("vin"));
        return super.result(res);
    }
    @PostMapping("/getTrialPhotosItems")
    @ApiOperation(value = "小程序根据项目编号获取实测条目")
    public ResultVO getTrialPhotosItems(@RequestBody Map<String, String> requestBody) {
        List<TakePhotoItemsEntity> res = service.getTrialPhotosItems(requestBody.get("prjNum"));
        return super.result(res);
    }
    @PostMapping("/getNormalTrialPhotosItems")
    @ApiOperation(value = "小程序根据项目编号获取通用实测条目")
    public ResultVO getNormalTrialPhotosItems(@RequestBody Map<String, String> requestBody) {
        List<TakePhotoItemsEntity> res = service.getNormalTrialPhotosItems(requestBody.get("prjNum"));
        return super.result(res);
    }
    @PostMapping("/getDeliveryLocation")
    @ApiOperation(value = "查询送达地点")
    public ResultVO getDeliveryLocation() {
        return service.getDeliveryLocation();
    }
    @PostMapping("/saveDeliveryRecord")
    @ApiOperation(value = "新增送达记录")
    public ResultVO saveDeliveryRecord(@RequestBody DeliveryVo vo) {
        return service.saveDeliveryRecord(vo);
    }
    @PostMapping("/updateDelivery")
    @ApiOperation(value = "更新送达记录")
    public ResultVO updateDelivery(@RequestBody DeliveryVo vo) {
        return service.updateDelivery(vo);
    }
    @PostMapping("/deleteDelivery")
    @ApiOperation(value = "更新送达记录")
    public ResultVO deleteDelivery(@RequestBody DeliveryVo vo) {
        return service.deleteDelivery(vo);
    }
    @PostMapping("/queryDeliveryRecord")
    @ApiOperation(value = "查询送达记录")
    public ResultVO queryDeliveryRecord(@RequestBody DeliveryVo vo) {
        String id = vo.getPlanId();
        List<DeliveryVo> lists = service.queryDeliveryRecord(id);
        return super.result(lists);
    }
    @PostMapping("/updateDeliveryRecord/state")
    @ApiOperation(value = "更新记录状态")
    public ResultVO updateDeliveryRecord(@RequestBody DeliveryVo vo) {
        return service.updateDeliveryRecord(vo);
    }

    @PostMapping("/saveReturnRecord")
    @ApiOperation(value = "新增还样记录")
    public ResultVO saveReturnRecord(@RequestBody ReturnVo vo) {
        return service.saveReturnRecord(vo);
    }
    @PostMapping("/updateReturnRecord")
    @ApiOperation(value = "更新还样记录")
    public ResultVO updateReturnRecord(@RequestBody ReturnVo vo) {
        return service.updateReturnRecord(vo);
    }
    @PostMapping("/queryReturnRecord")
    @ApiOperation(value = "查询送达记录")
    public ResultVO queryReturnRecord(@RequestBody ReturnVo vo) {
        String id = vo.getPlanId();
        List<ReturnVo> lists = service.queryReturnRecord(id);
        return super.result(lists);
    }
    @PostMapping("/deleteReturn")
    @ApiOperation(value = "删除送达记录")
    public ResultVO deleteReturn(@RequestBody DeliveryVo vo) {
        return service.deleteReturn(vo);
    }
    @PostMapping("/updateCarByVin")
    @ApiOperation(value = "更新车辆配置")
    public ResultVO updateCarByVin(@RequestBody TaskCarDTO vo) {
        return service.updateCarByVin(vo);
    }

    @PostMapping("/getCarConfig")
    @ApiOperation(value = "更新车辆配置")
    public ResultVO getCarConfig(@RequestBody TaskCarDTO vo) {
        String vin = vo.getVin();
        return service.getCarConfig(vin);
    }

    @PostMapping("/cleanAllFlow/{planId}")
    @ApiOperation(value = "清空所有流转记录")
    public ResultVO cleanAllFlow(@PathVariable Integer planId) {
        return service.cleanAllFlow(planId);
    }
//    //三个指派相关接口，新增指派，查询指派，删除指派
//    @PostMapping("/save/assign")
//    @ApiOperation(value = "新增指派项目")
//    public ResultVO saveAssign(@RequestBody CheckFileDetailByNameVo vo){
//
//        return null;
//    }

//    @PostMapping("/update")
//    @ApiOperation(value = "查看详情")
//    public ResultVO getDetail(@RequestBody CheckFileDetailByNameVo vo) {
//        Map<String, String> res = service.selectFileInfoById(vo);
//        return super.result(res);
//    }

}
